/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-09-24
 * Time:14:17
 */
//写一个泛型类，这个类中有一个方法，可以求最大值

class Alg<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            //if(max < array[i]) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Person implements Comparable<Person>{

    @Override
    public int compareTo(Person o) {
        return 0;
    }
}
class Alg1 {
    public <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg2 {
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test3 {
    public static void main(String[] args) {
        //静态泛型方法
        Integer[] array = {1,2,3,4,45,6,33};
        int max = Alg2.findMax(array);
        System.out.println(max);
    }
    public static void main3(String[] args) {
        Integer[] array = {1,2,3,4,45,6,33};
        Alg1 alg1 = new Alg1();
        int max = alg1.findMax(array);
        int max1 = alg1.<Integer>findMax(array);//显示传递实参，可省略
        System.out.println(max);
    }
    public static void main2(String[] args) {
        Alg<Person> alg = new Alg<Person>();
    }
    public static void main1(String[] args) {
        Integer[] array = {1,2,3,4,45,6,33};
        Alg<Integer> alg = new Alg<>();
        int max = alg.findMax(array);
        System.out.println(max);
    }
}
